package com.superteam.zzl.activity.SearchMoreActivity;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.superteam.zzl.activity.BaseActivity;
import com.superteam.zzl.activity.R;
import com.superteam.zzl.activity.databinding.ActivityShopMoreBinding;
import com.superteam.zzl.adapter.SearchAdapter.SearchResultAdapter;
import com.superteam.zzl.app.MyApplication;
import com.superteam.zzl.model.Search.ShopData;
import com.superteam.zzl.viewmodel.Search.RequestMoreData;

import java.util.ArrayList;

public class ShopMoreActivity extends BaseActivity {

    private ActivityShopMoreBinding shopMoreBinding;
    private ArrayList<Object> list;
    private SearchResultAdapter adapter;
    private ListView lv;
    private RequestMoreData moreData;
    private ShopData data;
    public static Handler handler;
    private int pageIndex=1;
    private ProgressBar pb;
    private EditText et;
    private TextView tv;
    @Override
    public void widgetClick(View v) {

    }

    @Override
    public ViewDataBinding initDataBinding() {
        shopMoreBinding = DataBindingUtil.setContentView(this,R.layout.activity_shop_more);
        lv = shopMoreBinding.lvShop;
        pb = shopMoreBinding.pbShopMore;
        tv = (TextView) findViewById(R.id.in_shop).findViewById(R.id.tv_search_1);
        et = (EditText) findViewById(R.id.in_shop).findViewById(R.id.et_search);
        et.setText(MyApplication.search);
        list = new ArrayList<>();
        adapter = new SearchResultAdapter(this,list);
        lv.setAdapter(adapter);
        lv.setEmptyView(pb);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(342,getIntent());
                finish();
            }
        });
        loadData();
        return shopMoreBinding;
    }

    private void loadData(){
        data = new ShopData();
        moreData = new RequestMoreData(data,pageIndex);
        handler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                for (int i = 0; i < data.productLists.size(); i++) {
                    list.add(data.productLists.get(i));
                }
                adapter.notifyDataSetChanged();
                return true;
            }
        });

    }
    @Override
    public void initParms(Bundle parms) {

    }

    @Override
    public View bindView() {
        return null;
    }

    @Override
    public void initView(View view) {

    }

    @Override
    public void setListener() {

    }

    @Override
    public void doBusiness(Context mContext) {

    }
}
